package wangm.service;

import wangm.bean.Notice;
import wangm.bean.NoticeQueryParameter;
import wangm.bean.Pagination;
import wangm.repository.NoticeRepository;
import wangm.util.RandomUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 通知service
 *
 * @author zk
 * @since 2018/5/8
 */
@Service
public class NoticeServiceImp {

    @Autowired
    private NoticeRepository noticeRepository;

    /**
     * 新增通知
     *
     * @param notice notice
     */
    public void add(Notice notice){
        notice.setId(RandomUtil.getUUID());
        notice.setCreateTime(new Date());
        noticeRepository.add(notice);
    }

    /**
     * 移除指定通知
     *
     * @param id id
     */
    public void remove(String id){
        noticeRepository.remove(id);
    }

    /**
     * 修改
     *
     * @param notice notice
     */
    public void modify(Notice notice){
        noticeRepository.modify(notice);
    }

    /**
     * 获取查询列表
     *
     * @param queryParameter 查询参数
     * @param pagination 分页数据
     * @return List<Notice></>
     */
    public List<Notice> getList(NoticeQueryParameter queryParameter, Pagination pagination){
        if(queryParameter == null){
            queryParameter = new NoticeQueryParameter();
        }

        return noticeRepository.getList(queryParameter,pagination);
    }

    /**
     * 获取指定id的通知
     *
     * @param id id
     * @return notice
     */
    public Notice get(String id){
        return noticeRepository.get(id);
    }
}
